﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using LeHouse.Server.Service;
using LeHouse.Server.Dto;
using LeHouse.Server.WebApi.Common;

namespace LeHouse.Server.WebApi.Controllers
{
    /// <summary>
    /// 项目跟踪与审核
    /// </summary>
    public class trackRecordController : ApiController
    {

    //  ///   <summary>
    //  ///   显示项目跟踪信息(根据xxx查询功能)
    //  ///   </summary>
    //  ///   <param name="S_name"></param>
    //  ///   <returns></returns>
    //    [HttpPost]
    //    [Route("api/trackRecord/select")]
    //    public List<TrackRecords> select([FromBody]string P_ReportNumber)
    //    {
    //        Personalservice personalservice = new Personalservice();
    //        Borrowerservice borrowerservice = new Borrowerservice();
    //        List<TrackRecords> list = new List<TrackRecords>();
    //        if (string.IsNullOrEmpty(P_ReportNumber))
    //        {
    //            var d1=personalservice.Select();
    //            foreach (var x in d1)
    //            {
    //                TrackRecords trackRecords = new TrackRecords();
    //                trackRecords.P_ReportNumber = x.P_ReportNumber;
    //                var d2=borrowerservice.Select().Where(p=>p.P_ReportNumber==x.P_ReportNumber).FirstOrDefault();
    //                if(d2!=null)
    //                {
    //                    trackRecords.B_id = d2.B_id.ToString();
    //                    trackRecords.B_name = d2.B_name;
    //                    trackRecords.B_phone = d2.B_phone;
    //                }
    //                list.Add(trackRecords);
    //            }
    //            return list;
    //        }
    //        else
    //        {
    //            var d1 = personalservice.Select().Where(p => p.P_ReportNumber .Contains(P_ReportNumber)).ToList();
    //            foreach (var x in d1)
    //            {
    //                TrackRecords trackRecords = new TrackRecords();
    //                trackRecords.P_ReportNumber = x.P_ReportNumber;
    //                var d2 = borrowerservice.Select().Where(p => p.P_ReportNumber == x.P_ReportNumber).FirstOrDefault();
    //                if (d2 != null)
    //                {
    //                    trackRecords.B_id = d2.B_id.ToString();
    //                    trackRecords.B_name = d2.B_name;
    //                    trackRecords.B_phone = d2.B_phone;
    //                }
    //                list.Add(trackRecords);
    //            }
    //            return list;
    //        }
    //    }


    /////  <summary>
    /////  显示审核列表（根据报告编号查询）
    /////  </summary>
    /////  <param name="S_name"></param>
    /////  <returns></returns>
    //[HttpPost]
    //    [Route("api/trackRecord/examinationSelect")]
    //    public List<TrackRecords> examinationSelect([FromBody]string P_ReportNumber)
    //    {
    //        Personalservice personalservice = new Personalservice();
    //        Borrowerservice borrowerservice = new Borrowerservice();
    //        List<TrackRecords> list = new List<TrackRecords>();
    //        if (string.IsNullOrEmpty(P_ReportNumber))
    //        {
    //            var d1 = personalservice.Select();
    //            foreach (var x in d1)
    //            {
    //                TrackRecords trackRecords = new TrackRecords();
    //                trackRecords.P_ReportNumber = x.P_ReportNumber;
    //                trackRecords.P_state = x.P_state;
    //                var d2 = borrowerservice.Select().Where(p => p.P_ReportNumber == x.P_ReportNumber).FirstOrDefault();
    //                if (d2 != null)
    //                {
    //                    trackRecords.B_id = d2.B_id.ToString();
    //                    trackRecords.B_name = d2.B_name;
    //                    trackRecords.B_phone = d2.B_phone;
    //                }
    //                list.Add(trackRecords);
    //            }
    //            return list;
    //        }
    //        else
    //        {
    //            var d1 = personalservice.Select().Where(p => p.P_ReportNumber.Contains(P_ReportNumber)).ToList();
    //            foreach (var x in d1)
    //            {
    //                TrackRecords trackRecords = new TrackRecords();
    //                trackRecords.P_ReportNumber = x.P_ReportNumber;
    //                trackRecords.P_state = x.P_state;
    //                var d2 = borrowerservice.Select().Where(p => p.P_ReportNumber == x.P_ReportNumber).FirstOrDefault();
    //                if (d2 != null)
    //                {
    //                    trackRecords.B_id = d2.B_id.ToString();
    //                    trackRecords.B_name = d2.B_name;
    //                    trackRecords.B_phone = d2.B_phone;
    //                }
    //                list.Add(trackRecords);
    //            }
    //            return list;
    //        }
    //    }


       ///// <summary>
       ///// 审核
       ///// </summary>
       ///// <param name="S_name"></param>
       ///// <returns></returns>
       // [HttpPost]
       // [Route("api/trackRecord/examinationUpdate")]
       // public dynamic examinationUpdate([FromBody]TrackRecords obj)
       // {
       //     jsonManager jm = new jsonManager();
       //     Personalservice personalservice = new Personalservice();
       //     Borrowerservice borrowerservice = new Borrowerservice();

       //     var d1 = personalservice.Select().Where(p => p.T_ReportNumber == obj.T_ReportNumber).FirstOrDefault();
       //     if(d1==null)
       //     {
       //         jm.code = 0;
       //         jm.msg = "根据该评估报告编号找不到信息！";
       //         return Json(jm);
       //     }

       //     if (obj.T_State==5|| obj.T_State==4)
       //     {
       //         if (d1.T_State != 3&&d1.T_State != 4)
       //         {
       //             jm.code = 0;
       //             jm.msg = "当前状态不能初审！";
       //             return Json(jm);
       //         }
       //         d1.T_State = Convert.ToInt32(obj.T_State);

       //     }
       //     else if (obj.T_State== 6 || obj.T_State== 7)
       //     {
       //         if (d1.T_State != 5 && d1.T_State != 6)
       //         {
       //             jm.code = 0;
       //             jm.msg = "当前状态不能终审！";
       //             return Json(jm);
       //         }
       //         d1.T_State = Convert.ToInt32(obj.T_State);
                
       //     }
       //     else
       //     {
       //         jm.code = 0;
       //         jm.msg = "状态参数不符合规则！";
       //         return Json(jm);
       //     }
            

       //    if( personalservice.Update(d1))
       //    {
       //        jm.code =1;
       //        jm.msg = "审核成功";
       //        return Json(jm);//代表审核成功
       //    }
       //     else
       //    {
       //        jm.code = 0;
       //        jm.msg = "执行审核，在最终修改数据时报错！";
       //        return Json(jm);
       //    }
          
       // }


        /// <summary>
        /// 获取枚举定义的状态
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Route("api/trackRecord/GetSelectState")]
        public dynamic GetSelectState()
        {
            var dropDic = EnumHelperDic.EnumListDic<EnumSelectState>(-1, "--请选择--");
            return Json(dropDic);
        }


    }


}
